package array;

public class SimpleArray {

    public void initialize() {
        //静态初始化
        int[] num1 = {1,0,0,1,1};

        Number[] numbers = {new Number(),new Number()};

        //动态初始化
        int[] num2 = new int[10];

    }

    public void useArray() {
        int sum = 0;
        int max = 0;
        int[] array = {1,2,4,7,8};
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        System.out.println(sum);
        for (int i = 0; i < array.length; i++) {
            if (max < array[i]) {
                max = array[i];
            }
        }
        System.out.println(max);
        for (int a:array) {
            System.out.print(a+" ");
        }
    }


    //变量的类型 变量的名字 = 变量的值
    public static void main(String[] args) {
        SimpleArray simple = new SimpleArray();
        //定义数组 Java风格
        int[] nums;
        //定义数组 C风格
        int[] num;
        //Java关键字new，创建数组空间
        nums = new int[10];
        //数组赋值
        nums[0] = 1;
        //数组求和
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
            //System.out.println(sum);
        }
        String[] chars = new String[10];
        //System.out.println(chars);

        simple.useArray();
    }
}
